<template>
  <avue-crud :option="option" :data="data" @row-update="addUpdate" @row-save="rowSave" @row-del="handleRowDelete"></avue-crud>
</template>

<script>
export default {
  name: 'tableQuery',
  props: {
    formData: {
      type: Array,
      default: () => []
    },
    isViewStatus: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    isViewStatus: {
      handler(val) {
        this.$set(this.option, 'addRowBtn', !val);
        this.$set(this.option, 'menu', !val);
        this.$set(this.option, 'editBtn', !val);
      },
      immediate: true
    }
  },
  data() {
    return {
      data: this._cloneDeep(this.formData),
      option: {
        border: true,
        addBtn: false,
        cellBtn: true,
        addRowBtn: true,
        viewBtn: false,
        editBtn: true,
        delBtn: true,
        index: true,
        menu: true,
        columnBtn: false,
        refreshBtn: false,
        indexLabel: '序号',
        column: [
          {
            label: '参数名称',
            prop: 'name',
            cell: true,
            minWidth: 150
          },
          {
            label: '参数字段',
            cell: true,
            prop: 'field',
            minWidth: 150
          },
          {
            label: '参数序号',
            cell: true,
            prop: 'sequence',
            minWidth: 150
          },
          {
            label: '控件类型',
            cell: true,
            prop: 'controlType',
            minWidth: 150,
            type: 'select',
            dicData: [
              {
                label: 'TEXT',
                value: 'TEXT'
              },
              {
                label: 'DATE',
                value: 'DATE'
              },
              {
                label: 'DATERANGE',
                value: 'DATERANGE'
              },
              {
                label: 'DATETIMERANGE',
                value: 'DATETIMERANGE'
              },
              {
                label: 'NUMBER',
                value: 'NUMBER'
              },
              {
                label: 'SELECT',
                value: 'SELECT'
              }
            ]
          },
          {
            label: '运算符',
            cell: true,
            prop: 'operator',
            span: 7,
            type: 'select',
            dicData: [
              {
                label: 'EQUALS',
                value: 'EQUALS'
              },
              {
                label: 'NOTEQUALS',
                value: 'NOTEQUALS'
              },
              {
                label: 'LIKE',
                value: 'LIKE'
              },
              {
                label: 'STARTSWITH',
                value: 'STARTSWITH'
              },
              {
                label: 'ENDSWITH',
                value: 'ENDSWITH'
              },
              {
                label: 'LESSTHAN',
                value: 'LESSTHAN'
              },
              {
                label: 'LESSTHANOREQUAL',
                value: 'LESSTHANOREQUAL'
              },
              {
                label: 'GREATERTHAN',
                value: 'GREATERTHAN'
              },
              {
                label: 'GREATERTHANOREQUAL',
                value: 'GREATERTHANOREQUAL'
              },
              {
                label: 'CONTAINS',
                value: 'CONTAINS'
              },
              {
                label: 'CONTAINSALL',
                value: 'CONTAINSALL'
              },
              {
                label: 'CONTAINSVALUE',
                value: 'CONTAINSVALUE'
              },
              {
                label: 'CONTAINSTEXT',
                value: 'CONTAINSTEXT'
              },
              {
                label: 'MATCHES',
                value: 'MATCHES'
              }
            ],
            minWidth: 150
          },
          {
            label: '传参方式',
            cell: true,
            prop: 'transferParametersMode',
            minWidth: 150,
            type: 'select',
            dicData: [
              {
                label: 'APPEND',
                value: 'APPEND'
              },
              {
                label: 'REPLACE',
                value: 'REPLACE'
              }
            ]
          },
          {
            label: '参数转换SQL',
            cell: true,
            prop: 'convertSql',
            minWidth: 150
          },
          {
            label: '数据源',
            cell: true,
            prop: 'controlData',
            minWidth: 150
          },
          {
            label: '默认值',
            cell: true,
            prop: 'defaultValue',
            minWidth: 150
          }
        ]
      }
    };
  },
  methods: {
    rowSave(row, done, loading) {
      this.$emit('change', this.data);
      done();
    },
    addUpdate(row, index, done, loading) {
      console.log(this.data);
      this.$emit('change', this.data);
      done();
    },
    handleRowDelete(row, index) {
      this.data.splice(index, 1);
      console.log(this.data);
      this.$emit('change', this.data);
    }
  }
};
</script>

<style scoped></style>
